import program from "commander";
import { VERSION } from "./utils/constants";
//多种功能命令
let actionMap = {
    install: {//配置命令的名字
        alias: 'i',//命令别的名称
        description: 'install template', //命令对应的描述
        examples: [//命令对应的模板
            'yq-babel-cli i',
            'yq-babel-cli install'
        ]
    },
    config: {
        alias: 'c',
        description: 'config .zfclirc',
        examples: [
            'yq-babel-cli config set <k> <v>',
            'yq-babel-cli config get <k>',
            'yq-babel-cli config remove <k>'
        ]
    },
    '*': {
        description: 'not found',
        examples: []
    }
}

Object.keys(actionMap).forEach(action => {
    program.command(action)
        .description(actionMap[action].description)
        .alias(actionMap[action].alias)
        .action(() => {
            //console.log(action)
            //判断一下当前用的是什么操作
            if (action === 'config') {
                //实现更改配置文件
                //console.log(process.argv)//数组
                main(action, process.argv.slice(3));
            } else if (action === 'install') {

            }
            main()
        })
})

function help() {
    // console.log('123')//把example显示出去
    console.log('\r\n  ' + 'how to use command');
    Object.keys(actionMap).forEach(action => {
        actionMap[action].examples.forEach(example => {
            console.log('  - ' + example)
        })
    })
}
program.on('-h', help);
program.on('--help', help);
program.version(VERSION, '-v --version').parse(process.argv);